package br.unifor.aspect;

import javassist.gluonj.Glue;
import javassist.gluonj.Refine;
import br.unifor.onto.ServiceHelper;

import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.impl.ResourceImpl;
import com.hp.hpl.jena.shared.PropertyNotFoundException;

@Glue
class PropertyInterceptor
{

	@Refine( "com.hp.hpl.jena.ontology.impl.OntResourceImpl" )
	static class OntResourceImplNew extends ResourceImpl
	{
		public RDFNode getPropertyValue( Property property )
		{
			try
			{
				System.out.println( "Interceptando..." );

				try
				{
					if ( ServiceHelper.existActivelowlAnnotation( property ) )
						return ServiceHelper.invokeService( (Individual) this,
							property );
				}
				catch ( Exception e )
				{
					e.printStackTrace();
				}

				return getRequiredProperty( property ).getObject();
			}
			catch ( PropertyNotFoundException ignore )
			{
				return null;
			}
		}
	}
}
